package com.zzmcc.wechat.service.impl;

import com.zzmcc.wechat.entity.Account;
import com.zzmcc.wechat.service.AccountService;
import org.smart4j.framework.orm.DataSet;
import org.smart4j.framework.tx.annotation.Service;
import org.smart4j.framework.tx.annotation.Transaction;

import java.beans.Transient;
import java.util.List;
import java.util.Map;

/**
 * Created by joinwin on 14-7-1.
 */
@Service
public class AccountServiceImpl implements AccountService {
    @Override
    public boolean saveAccount(Map<String, Object> fieldMap) {
        return  DataSet.insert(Account.class,fieldMap);
    }
    @Override
    public List<Account> getAccounts(String keyword){
        String condition = "account like ?";
        Object[] params ={"%" +keyword+"%"};
        return  DataSet.selectListWithCondition(Account.class, condition, params);
    }
    @Override
    @Transaction
    public  boolean delAccount(long id){
        return  DataSet.delete(Account.class,"id=?",id);
    }
    @Override
    public  Account findAccount(long id){
        return  DataSet.select(Account.class,"id = ?",id);
    }
    @Override
    public boolean updateAccount(long id,Map<String,Object>fieldMap){
        boolean result = DataSet.update(Account.class,fieldMap,"id = ?",id);
        return  result;

    }
}
